/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.com.apresentacao.pedagogico;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import src.com.dados.pedagogico.AlunoDao;
import src.com.dados.pedagogico.NivellDao;
import src.com.dados.pedagogico.TurmaDao;
import src.com.negocio.pedagogico.CadastrarIdioma;
import src.com.negocio.pedagogico.CadastrarNivelIdioma;
import src.com.negocio.pedagogico.CadastrarTurma;
import src.com.negocio.pedagogico.ConsultarTurma;

/**
 *
 * @author Giane
 */
public class CadastroTurma extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    private String codigo;

    public CadastroTurma() throws SQLException {
        initComponents();
        CadastrarIdioma c = new CadastrarIdioma();
        for (int i = 0; i < c.consultaIdioma().size(); i++) {
            i_idioma.addItem(c.consultaIdioma().get(i));
            //System.out.print(c.consultaIdioma().get(i));            
        }
        CadastrarNivelIdioma d = new CadastrarNivelIdioma();
        for (int i = 0; i < d.consultaNivel().size(); i++) {
            nivelCurso.addItem(d.consultaNivel().get(i));
            //System.out.print(c.consultaIdioma().get(i));            
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jInternalFrame2 = new javax.swing.JInternalFrame();
        jLabel1 = new javax.swing.JLabel();
        codTurma = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        v_vagas = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        nivelCurso = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        hrInicio = new javax.swing.JComboBox();
        hrFim = new javax.swing.JComboBox();
        BT_Cadastrar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        dtInicio = new javax.swing.JFormattedTextField();
        dtFim = new javax.swing.JFormattedTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        i_idioma = new javax.swing.JComboBox();
        BT_Remover = new javax.swing.JButton();
        BT_Alunos = new javax.swing.JButton();
        dia_1 = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        dia_2 = new javax.swing.JComboBox();
        prof = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jInternalFrame2.setTitle("Cadastro - Turma");
        jInternalFrame2.setToolTipText("");
        jInternalFrame2.setVisible(true);

        jLabel1.setText("Código de Turma:");
        jLabel1.setToolTipText("");

        codTurma.setToolTipText("");
        codTurma.setName("codTurma"); // NOI18N
        codTurma.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                codTurmaActionPerformed(evt);
            }
        });

        jLabel2.setText("Vagas: ");
        jLabel2.setToolTipText("");

        v_vagas.setName("vagasTurmas"); // NOI18N
        v_vagas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                v_vagasActionPerformed(evt);
            }
        });

        jLabel3.setText("Nível do Curso:");

        nivelCurso.setName("nivel"); // NOI18N
        nivelCurso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nivelCursoActionPerformed(evt);
            }
        });

        jLabel4.setText("Horário:");

        jLabel5.setText("às");

        jLabel6.setText("Dias:");

        hrInicio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00" }));
        hrInicio.setName("hrInicio"); // NOI18N
        hrInicio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                hrInicioActionPerformed(evt);
            }
        });

        hrFim.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00" }));
        hrFim.setName("hrFim"); // NOI18N

        BT_Cadastrar.setText("Cadastrar");
        BT_Cadastrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                BT_CadastrarMouseClicked(evt);
            }
        });

        jLabel7.setText("Data Início: ");

        dtInicio.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
        dtInicio.setName("dtInicio"); // NOI18N
        dtInicio.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                dtInicioPropertyChange(evt);
            }
        });

        dtFim.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));
        dtFim.setName("dtFim"); // NOI18N

        jLabel9.setText("Professor: ");

        jLabel10.setText("Data Fim: ");

        jLabel8.setText("Idioma: ");

        i_idioma.setName("idioma"); // NOI18N

        BT_Remover.setText("Remover");
        BT_Remover.setEnabled(false);
        BT_Remover.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                BT_RemoverMouseClicked(evt);
            }
        });
        BT_Remover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BT_RemoverActionPerformed(evt);
            }
        });

        BT_Alunos.setText("Alunos");
        BT_Alunos.setEnabled(false);
        BT_Alunos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                BT_AlunosMouseClicked(evt);
            }
        });

        dia_1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado" }));

        jLabel11.setText("e");

        dia_2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado" }));

        javax.swing.GroupLayout jInternalFrame2Layout = new javax.swing.GroupLayout(jInternalFrame2.getContentPane());
        jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout);
        jInternalFrame2Layout.setHorizontalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel8)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jLabel9)
                        .addGap(42, 42, 42)))
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(prof, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addComponent(hrInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(hrFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(17, 17, 17)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dia_1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(dia_2, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jInternalFrame2Layout.createSequentialGroup()
                            .addComponent(BT_Alunos)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(BT_Remover)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(BT_Cadastrar))
                        .addGroup(jInternalFrame2Layout.createSequentialGroup()
                            .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(codTurma, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(v_vagas, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(i_idioma, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jLabel7))
                                .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                    .addGap(7, 7, 7)
                                    .addComponent(jLabel3)))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jInternalFrame2Layout.createSequentialGroup()
                                    .addComponent(dtInicio, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(jLabel10)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(dtFim, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(nivelCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(34, Short.MAX_VALUE))
        );
        jInternalFrame2Layout.setVerticalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(codTurma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(v_vagas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(dtInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(dtFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(nivelCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(i_idioma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel8))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(hrInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(hrFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(dia_1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(dia_2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(prof, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BT_Cadastrar)
                    .addComponent(BT_Remover)
                    .addComponent(BT_Alunos))
                .addContainerGap(55, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jInternalFrame2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BT_RemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BT_RemoverActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_BT_RemoverActionPerformed

    private void dtInicioPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_dtInicioPropertyChange
    }//GEN-LAST:event_dtInicioPropertyChange

    private void nivelCursoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nivelCursoActionPerformed
    }//GEN-LAST:event_nivelCursoActionPerformed

    private void BT_AlunosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BT_AlunosMouseClicked
        AlunoDao alu = new AlunoDao();
        try {
            ArrayList<String> alunos = alu.listaAlunos(codTurma.getText().toString());

            if (!alunos.isEmpty()) {
                ListaAlunos list = new ListaAlunos();
                list.initValue(alunos);
                list.setVisible(true);
            } else {
                javax.swing.JDialog inf = new javax.swing.JDialog();
                inf.setSize(250, 150);
                javax.swing.JOptionPane.showMessageDialog(inf, "Não existe Alunos nesta Turma!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);

            }



        } catch (SQLException ex) {
            Logger.getLogger(CadastroTurma.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_BT_AlunosMouseClicked

    private void BT_CadastrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BT_CadastrarMouseClicked
        String codigo = codTurma.getText().toString();
        String vagas = v_vagas.getText().toString();
        String dataInicio = dtInicio.getText().toString();
        String dataFim = dtFim.getText().toString();
        String idioma = i_idioma.getSelectedItem().toString();
        String nivel = nivelCurso.getSelectedItem().toString();
        String dia1 = dia_1.getSelectedItem().toString();
        String dia2 = dia_2.getSelectedItem().toString();
        String horaInicio = hrInicio.getSelectedItem().toString();
        String horaFim = hrFim.getSelectedItem().toString();
        String professor = prof.getText().toString();


        CadastrarTurma B = new CadastrarTurma();
        try {
            if (B.VerificarTurma(codigo).equals("0")) {
                if (B.VerificarProfessor(professor).equals("1")) {
                    B.cadastrarTuma(codigo, vagas, dataInicio, dataFim, idioma, nivel, dia1, dia2, horaInicio, horaFim, professor);
                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);
                    javax.swing.JOptionPane.showMessageDialog(inf, "Cadastro realizado com Sucesso!", "Informação", javax.swing.JOptionPane.INFORMATION_MESSAGE);

                } else {
                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);
                    javax.swing.JOptionPane.showMessageDialog(inf, "O professor informado não existe!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);

                }
            } else {
                javax.swing.JDialog inf = new javax.swing.JDialog();
                inf.setSize(250, 150);
                javax.swing.JOptionPane.showMessageDialog(inf, "O código informado já existe!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);
            }






        } catch (SQLException ex) {
            Logger.getLogger(CadastroTurma.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_BT_CadastrarMouseClicked

    private void hrInicioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hrInicioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_hrInicioActionPerformed

    private void v_vagasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_v_vagasActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_v_vagasActionPerformed

    private void codTurmaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codTurmaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_codTurmaActionPerformed

    private void BT_RemoverMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_BT_RemoverMouseClicked
        TurmaDao cons = new TurmaDao();
        try {
            String count = cons.verificarTurmaMatricula(codTurma.getText());


            int resposta = javax.swing.JOptionPane.showConfirmDialog(null, "Tem certeza que desaja excluir Turma?");

            if (resposta == JOptionPane.YES_OPTION) {
                if (count.equals("0")) {
                    cons.removerTurma(codTurma.getText().toString());

                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);

                    javax.swing.JOptionPane.showMessageDialog(inf, "Turma excluida com sucesso!", "Informação", javax.swing.JOptionPane.INFORMATION_MESSAGE);

                } else {
                    javax.swing.JDialog inf = new javax.swing.JDialog();
                    inf.setSize(250, 150);

                    javax.swing.JOptionPane.showMessageDialog(inf, "Turma não pode ser excluida. Existe Aluno Matriculado!", "Informação", javax.swing.JOptionPane.WARNING_MESSAGE);


                }
            }



            // alertar
            //javax.swing.JDialog f = new javax.swing.JDialog();
            //f.setSize(250, 150);



            //f.setVisible(true);


        } catch (SQLException ex) {
            Logger.getLogger(CadastroTurma.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_BT_RemoverMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CadastroTurma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CadastroTurma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CadastroTurma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CadastroTurma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new CadastroTurma().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(CadastroTurma.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BT_Alunos;
    private javax.swing.JButton BT_Cadastrar;
    private javax.swing.JButton BT_Remover;
    private javax.swing.JTextField codTurma;
    private javax.swing.JComboBox dia_1;
    private javax.swing.JComboBox dia_2;
    private javax.swing.JFormattedTextField dtFim;
    private javax.swing.JFormattedTextField dtInicio;
    private javax.swing.JComboBox hrFim;
    private javax.swing.JComboBox hrInicio;
    private javax.swing.JComboBox i_idioma;
    private javax.swing.JInternalFrame jInternalFrame2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JComboBox nivelCurso;
    private javax.swing.JTextField prof;
    private javax.swing.JTextField v_vagas;
    // End of variables declaration//GEN-END:variables

    void setTurma(String cod_turma) {
        this.codigo = cod_turma;
    }

    public String getcodTurma() {
        return this.codigo;
    }

    void initValue() throws SQLException {
        if (getcodTurma() != null) {

            ConsultarTurma p = new ConsultarTurma();
            ArrayList<String> result_turma = p.consultaTurma2(codigo, "", "", "");


            System.out.print("hgffhdgf" + result_turma);

            CadastrarIdioma c = new CadastrarIdioma();
            CadastrarNivelIdioma r = new CadastrarNivelIdioma();

            ArrayList<String> t = c.consultaIdioma();
            ArrayList<String> j = r.consultaNivel();

            for (int i = 0; i < t.size(); i++) {
                if (result_turma.get(8).toString().equals(t.get(i).toString())) {
                    i_idioma.setSelectedIndex(i);
                }

            }

            for (int i = 0; i < j.size(); i++) {
                if (result_turma.get(10).toString().equals(j.get(i).toString())) {
                    nivelCurso.setSelectedIndex(i);
                }

            }

            ArrayList<String> horarios = new ArrayList<String>(Arrays.asList("08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00"));

            for (int i = 0; i < j.size(); i++) {
                if (result_turma.get(6).equals(horarios.get(i).toString())) {
                    hrInicio.setSelectedIndex(i);
                }

            }
            for (int i = 0; i < j.size(); i++) {
                if (result_turma.get(7).equals(horarios.get(i).toString())) {
                    hrFim.setSelectedIndex(i);
                }

            }


            codTurma.setText(result_turma.get(0));
            v_vagas.setText(result_turma.get(1));
            dtInicio.setText(result_turma.get(2));
            dtFim.setText(result_turma.get(3));
            prof.setText(result_turma.get(9));

            BT_Remover.setEnabled(true);
            BT_Alunos.setEnabled(true);


        }
    }
}
